package com.copc.service.impl;

import com.alibaba.fastjson2.JSON;
import com.alibaba.fastjson2.JSONArray;
import com.alibaba.fastjson2.JSONObject;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.copc.common.config.Config;
import com.copc.common.constants.CacheConstants;
import com.copc.common.constants.Constant;
import com.copc.common.service.RedisService;
import com.copc.common.util.BytedancePayVerifyUtil;
import com.copc.common.util.CommonUtil;
import com.copc.copc.entity.MerchantConfig;
import com.copc.copc.entity.OrderMessage;
import com.copc.copc.pojo.vo.order.*;
import com.copc.copc.service.IMerchantConfigService;
import com.copc.copc.service.IOrderMessageService;
import com.copc.mq.bean.SysConstant;
import com.copc.service.CopcService;

import java.math.BigDecimal;
import java.security.SecureRandom;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors;
import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.*;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * 订单分发相关服务
 */
@Slf4j
@Service
public class CopcServiceImpl implements CopcService {

    @Resource
    private RedisService redisService;

    @Resource
    private MsgServiceImpl msgService;

    @Resource
    private IMerchantConfigService merchantConfigService;

    @Resource
    private IOrderMessageService orderMessageService;

    /**
     * 授权登录接口地址
     */
    public static final String code2SessionStr = "https://developer.toutiao.com/api/apps/v2/jscode2session";

    /**
     * 查询用户券接口地址
     */
    public static final String queryCertificatesStr = "https://open.douyin.com/api/trade/v2/fulfillment/query_user_certificates";

    /**
     * 券加锁
     */
    public static final String lockCertificatesStr = "https://open.douyin.com/api/apps/trade/v2/toolkit/change_lock_status";

    /**
     * 查询订单可用门店地址
     */
    public static final String orderCanUseStr = "https://open.douyin.com/api/trade/v2/fulfillment/order_can_use";


    //public static final String PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAt6bnyxD0Ro+qYwgFi5bRiwdNBJTT0CdPOCr6a0OR0RjgrAD+4lsWrNFZZcv+Jqdk3FetlPGzZxipMNlVT7JzdBvCOFPe+slgoEfArwIUGAmo9SRMi/Dtoi+gA8FLL0K5FQLq/SYbVM/APYRYE06HIXcp+CNvrBJ7zl1+uvxRavGHRNnrT3DHhfTQNd0yuXR/PAsGngAp0aqy7RPcjkpNJZbX/QzrljjBpRjFu4ef6LGvIkswaJ1FzPXHVLRVAAgsei7ZX9l4RUoSaosRSILj1ZYp8UTXdjMwXbImplbBPmdcDNgVXCE9KhPhFV47/jQOUkeIZ8FtKIh8Czq8hZLwIDAQAB";

    public static final String PUBLIC_KEY = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAmUhzXBX7YXf21WHsRCVjgVRI4w3F4369X2Hr7q2jRXzJizylfN+gW7wolElh8yWBKZCfd+Hv49vDQRHBGzwy4hpS03egFcEdtk5FMKS6+NaEKa89ByhcIVT2dB0AhiL9KVTAOd0xUorSKoqmzS5oJucs0jajctbf9F/0X6hLQOhKMcPbv0see4vqQRbi5WWGp5Zue/m+7dZIYPSR7xdLpaOw0nMieKoKw+6EH9ESEAdK6ghSHmLmDtXH758W/ceAz6HRMlaADOIvWHRaKfWR7e91v4nLi5Lvz/Pxtfmq8weW+0tUt5MufynUvABAPVsOXM2XHX/SYJtkukcpoxRo8wIDAQAB";

    private Random random = new SecureRandom();

    /**
     * 订单入库
     *
     * @param msg
     */
    @Override
    public void saveOrder(String msg) {
        log.info("订单入库 : {}", msg);
        Map<String, Object> map = JSON.parseObject(msg, Map.class);
        String orderNo = map.get("order_id").toString();
        String orderstr = redisService.getCacheObject(CacheConstants.COPC_ISV_ORDER_CACHE_KEY + orderNo);
        log.info("orderstr : {}", orderstr);
        if (CommonUtil.isNotEmpty(orderstr)) {
            QueryWrapper<OrderMessage> orderMessageWrapper = new QueryWrapper();
            orderMessageWrapper.eq("order_no", orderNo);//启用的商户配置
            List<OrderMessage> lists = orderMessageService.list(orderMessageWrapper);
            if (CommonUtil.isNotEmpty(lists) && lists.size() > 0) {
                OrderMessage orderMessage = lists.get(0);
                orderMessage.setPayedMessage(msg);
                orderMessage.setStatus(Constant.ORDER_STATUS_PAYED);
                orderMessageService.saveOrUpdate(orderMessage);
            } else {
                String appId = map.get("app_id").toString();
                Date now = new Date();
                OrderMessage orderMessage = new OrderMessage();
                orderMessage.setOrderNo(orderNo);
                orderMessage.setCreatedTime(now);
                orderMessage.setUpdatedTime(now);
                orderMessage.setMerchantId(appId);
                orderMessage.setStatus(Constant.ORDER_STATUS_PAYED);
                orderMessage.setCreateOrderMessage(orderstr);
                orderMessage.setPayedMessage(msg);
                orderMessageService.save(orderMessage);
            }
        }
        //支付或取消订单删除缓存信息
        redisService.expire(CacheConstants.COPC_ISV_ORDER_CACHE_KEY + orderNo, CacheConstants.EXPIRED + random.nextInt(60), TimeUnit.SECONDS);
    }

    /**
     * 取消订单处理
     *
     * @param msg
     */
    @Override
    public void cancelOrder(String msg) {
        Map<String, Object> map = JSON.parseObject(msg, Map.class);
        String orderNo = map.get("order_id").toString();
        QueryWrapper<OrderMessage> orderMessageWrapper = new QueryWrapper();
        orderMessageWrapper.eq("order_no", orderNo);//启用的商户配置
        List<OrderMessage> lists = orderMessageService.list(orderMessageWrapper);
        if (CommonUtil.isNotEmpty(lists) && lists.size() > 0) {
            OrderMessage orderMessage = lists.get(0);
            orderMessage.setCancelMessage(msg);
            orderMessage.setStatus(Constant.ORDER_STATUS_CANCEL);
            orderMessageService.saveOrUpdate(orderMessage);
        }
        //支付或取消订单删除缓存信息
        redisService.expire(CacheConstants.COPC_ISV_ORDER_CACHE_KEY + orderNo, CacheConstants.EXPIRED + random.nextInt(60), TimeUnit.SECONDS);
    }

    /**
     * 验签请求处理
     *
     * @param request
     * @return
     */
    @Override
    public boolean verify(String body, HttpServletRequest request) throws Exception {
        try {
            String signStr = request.getHeader("Byte-Signature");
            String timestamp = request.getHeader("Byte-Timestamp");
            String nonce = request.getHeader("Byte-Nonce-Str");
            log.info("body:" + body + ",signStr:" + signStr + ",timestamp:" + timestamp + ",nonce:" + nonce);
            boolean flag = BytedancePayVerifyUtil
                    .verify(body, PUBLIC_KEY, signStr,
                            Long.parseLong(timestamp), nonce);
            return flag;
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return false;
    }

    /**
     * 券核销分发订单
     *
     * @param msg
     */
    @Override
    public void voucherVerification(String msg) {
        log.info("券核销分发订单 : {}", msg);
        ByteVerifyMsg byteVerifyMsg = JSON.parseObject(msg, ByteVerifyMsg.class);
        String orderNo = byteVerifyMsg.getOrder_info().getOrder_id();
        QueryWrapper<OrderMessage> orderMessageWrapper = new QueryWrapper();
        orderMessageWrapper.eq("order_no", orderNo);//启用的商户配置
        List<OrderMessage> lists = orderMessageService.list(orderMessageWrapper);
        log.info("orderlist orderNo : {},size :{}", orderNo, lists.size());
        if (CommonUtil.isNotEmpty(lists) && lists.size() > 0) {
            OrderMessage orderMessage = lists.get(0);
            String createOrderMessage = orderMessage.getCreateOrderMessage();
            //获取原订单信息
            ByteMsgVO byteMsgVO = JSON.parseObject(createOrderMessage, ByteMsgVO.class);
            //组装分发订单信息
            MsgOrderStartBook msgOrderStartBook = new MsgOrderStartBook();
            msgOrderStartBook.setBeginTime(byteMsgVO.getCreate_order_time());//下单时间
            BigDecimal totalAmount = new BigDecimal(byteMsgVO.getTotal_amount()).divide(new BigDecimal("100"), 2, BigDecimal.ROUND_DOWN);
            BigDecimal discountAmount = new BigDecimal(byteMsgVO.getDiscount()).divide(new BigDecimal("100"), 2, BigDecimal.ROUND_DOWN);
            msgOrderStartBook.setAmount(totalAmount);//金额 等于总金额减去优惠金额
            msgOrderStartBook.setNo(byteMsgVO.getOrder_id());//订单号
            String payedMessage = orderMessage.getPayedMessage();

            log.info("voucherVerification : payedMessage : {}", payedMessage);
            BytePayedVO bytePayedVO = JSON.parseObject(payedMessage, BytePayedVO.class);
            msgOrderStartBook.setMerchantOrderNo(bytePayedVO.getOut_order_no());//开发者订单号
            String byteExtraStr = byteMsgVO.getCp_extra();
            ByteExtraVO byteExtraVO = JSON.parseObject(byteExtraStr, ByteExtraVO.class);
            if (CommonUtil.isNotEmpty(byteExtraVO)) {
                msgOrderStartBook.setComment(byteExtraVO.getRemark());//备注
                msgOrderStartBook.setPickupTime(byteExtraVO.getPickupTime());//取件时间
                msgOrderStartBook.setSendAddressVO(byteExtraVO.getSendAddressVO());//发件地址
                msgOrderStartBook.setTakeAddressVO(byteExtraVO.getTakeAddressVO());//取件地址
            }
            String thirdskuid = byteExtraVO.getThird_sku_id();//获取第三方skuid
            msgOrderStartBook.setMobile(byteExtraVO.getPhone_num());//手机号
            msgOrderStartBook.setOpenShopId(byteVerifyMsg.getPoi_id().toString());//核销门店ID
            List<ByteSkuListVO> goods = byteMsgVO.getSku_list();
            List<ProductVO> productVOList = new ArrayList<ProductVO>();
            if (CommonUtil.isNotEmpty(goods) && goods.size() > 0) {
                ProductVO productVO;
                for (ByteSkuListVO byteSkuListVO : goods) {
                    productVO = new ProductVO();
                    productVO.setApp_product_id(byteSkuListVO.getSku_id());
                    productVO.setApp_sku_id(thirdskuid);
                    if (CommonUtil.isNotEmpty(byteSkuListVO.getGoods_info())) {
                        productVO.setProduct_name(byteSkuListVO.getGoods_info().getTitle());
                    }
                    productVO.setAmount(new BigDecimal((byteSkuListVO.getPrice() * byteSkuListVO.getQuantity())).divide(new BigDecimal("10000"), 2, BigDecimal.ROUND_DOWN));
                    productVO.setQuantity(byteSkuListVO.getQuantity());
                    productVOList.add(productVO);
                }
            }
            msgOrderStartBook.setProductVOList(productVOList);
            //组装优惠信息
            List<OrderShoppromoDetailsVO> shoppromoDetailsVOS = byteVerifyMsg.getCoupon_verify_results();
            if (CommonUtil.isNotEmpty(shoppromoDetailsVOS)) {
                msgOrderStartBook.setOrderShoppromoDetailsVOList(shoppromoDetailsVOS);
            }

            QueryWrapper<MerchantConfig> merchantConfigWrapper = new QueryWrapper();
            merchantConfigWrapper.eq("account_id", byteExtraVO.getAccount_id());//启用的商户配置
            MerchantConfig merchantConfig = merchantConfigService.getOne(merchantConfigWrapper);
            String MerchantMessage = merchantConfig.getMessage();

//            List<OrderShoppromoDetailsVO> couponVerifyResults = byteVerifyMsg.getCoupon_verify_results();
//
//            JSONArray certificates = new JSONArray();
//            for(OrderShoppromoDetailsVO orderShoppromoDetailsVO :couponVerifyResults ){
//                JSONObject jsonObject = new JSONObject();
//                jsonObject.put("certificate_id",orderShoppromoDetailsVO.getCertificate_id());
//                certificates.add(jsonObject);
//            }
//
//            String deductOrderId = byteMsgVO.getSku_list().get(0).getDiscount_info().getDeduct_info().getDeduct_order_id();
//
//            //券加锁
//            this.lockCertificate(byteVerifyMsg.getApp_id(),deductOrderId,certificates,2);

            //分发订单到商城中心
            log.info("分发订单到商城中心msgOrderStartBook:mesage : {} , body : {}", MerchantMessage, JSON.toJSONString(msgOrderStartBook));
            //msgService.sendMsg(MerchantMessage,JSON.toJSONString(msgOrderStartBook));
            msgService.sendMessage(byteExtraVO.getAccount_id(), MerchantMessage, JSON.toJSONString(msgOrderStartBook));
            orderMessage.setVoucherMessage(msg);
            orderMessage.setStatus(Constant.ORDER_STATUS_VERFIED);
            orderMessageService.saveOrUpdate(orderMessage);


        }
    }

//    public void lockCertificate(String appId, String orderId, JSONArray certificates,int operationType) {
//
//        try {
//            HttpHeaders headers = new HttpHeaders();
//            headers.setContentType(MediaType.APPLICATION_JSON);
//            headers.set("access-token", getClientToken(appId));
//
//            JSONObject requestBody = new JSONObject();
//            JSONObject orderInfo = new JSONObject();
//            orderInfo.put("order_id", orderId);
//
////        JSONObject timesCardLockInfo = new JSONObject();
////        timesCardLockInfo.put("lock_count", 10);
////
////        certificateInfo.put("times_card_lock_info", timesCardLockInfo);
//
//            orderInfo.put("certificate_info_list", certificates);
//            orderInfo.put("lock_key", "1704698496438");
//
//            requestBody.put("order_info_list", new JSONObject[]{orderInfo});
//            requestBody.put("operation_type", operationType);
//
//            HttpEntity<String> requestEntity = new HttpEntity<>(requestBody.toString(), headers);
//
//            ResponseEntity<String> response = restTemplate.exchange(lockCertificatesStr, HttpMethod.POST, requestEntity, String.class);
//
//            log.info("lockCertificate response : {}",response);
//
//        }catch (Exception e){
//
//            log.info("isv锁定券失败");
//        }
//
//
//    }

    /**
     * 刷新AccessToken接口
     */
    @Override
    public void refreshAccessToken() {
        String appId = Config.getInstance().getValue("appId");
        String configToken = redisService.getCacheObject(CacheConstants.COPC_ISV_CLIENT_TOKEN_KEY + appId);
        if (CommonUtil.isNotEmpty(configToken)) {
            log.info("token：" + configToken);
            return;
        }
        log.info("刷新token任务");
        getClientToken(appId);
    }

    /**
     * 生成client_token接口
     */
    public static final String clientTokenStr = "https://open.douyin.com/oauth/client_token/";

    @Autowired
    private RestTemplate restTemplate;

    @Override
    public String getClientToken(String appid) {
        String tokenStr = redisService.getCacheObject(CacheConstants.COPC_ISV_CLIENT_TOKEN_KEY + appid);
        if (CommonUtil.isNotEmpty(tokenStr)) {
            return tokenStr;
        }
        String secret = Config.getInstance().getValue("appSercet");

        Map<String, String> param = new HashMap<>();
        param.put("grant_type", "client_credential");
        param.put("client_key", appid);
        param.put("client_secret", secret);
        String response = restTemplate.postForObject(clientTokenStr,
                param, String.class);
        log.info(response.toString());
        JSONObject jsonObject = JSON.parseObject(response);
        if ("success".equals(jsonObject.get("message").toString())) {
            JSONObject data = jsonObject.getJSONObject("data");
            tokenStr = data.get("access_token").toString();
            redisService.setCacheObject(CacheConstants.COPC_ISV_CLIENT_TOKEN_KEY + appid, tokenStr, 100l, TimeUnit.MINUTES);
        }
        return tokenStr;
    }

    /**
     * 获取商品goodID
     *
     * @param skuids
     * @return
     */
    @Override
    public Map<String, GoodsInfoVO> getGoodIdByskuids(List<String> skuids, String accountId) {
        String goodsUrl = Config.getInstance().getValue("goodsUrl");

        QueryWrapper<MerchantConfig> merchantConfigWrapper = new QueryWrapper();
        merchantConfigWrapper.eq("account_id", accountId);//启用的商户配置
        MerchantConfig merchantConfig = merchantConfigService.getOne(merchantConfigWrapper);

        String getGoodsUrl = merchantConfig.getAuthUrl() + goodsUrl;


        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
        Map<String, List> param = new HashMap<>();
        param.put("skuids", skuids);
        HttpEntity<Map> entity = new HttpEntity<Map>(param, headers);
        String response = restTemplate.postForObject(getGoodsUrl,
                entity, String.class);
        log.info(response.toString());
        Map<String, GoodsInfoVO> maps = new HashMap<>();
        try {
            List<GoodsInfoVO> goodsInfoVOList = JSON.parseArray(response, GoodsInfoVO.class);
            if (CommonUtil.isNotEmpty(goodsInfoVOList)) {
                for (GoodsInfoVO goodsInfoVO : goodsInfoVOList) {
                    maps.put(goodsInfoVO.getSkuId(), goodsInfoVO);
                }
            }
        } catch (Exception e) {
            log.error(e.getMessage());
        }
        return maps;
    }

    @Override
    public String code2Session(String code, String appId) {
        String secret = Config.getInstance().getValue("appSercet");
        //获取用户openid
        Map<String, String> param = new HashMap<>();
        param.put("appid", appId);
        param.put("secret", secret);
        param.put("code", code);
//        param.put("anonymous_code", "");
        String response = restTemplate.postForObject(code2SessionStr,
                param, String.class);
        log.info(response.toString());
        return response;
    }

    @Override
    public String queryCertificates(String appId, String accountId, String openId, String page, String pageSize) {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
        headers.add("access-token", getClientToken(appId));
        //查询用户券接口
        Map<String, String> param = new HashMap<>();
        param.put("app_id", appId);
        param.put("open_id", openId);
        param.put("account_id", accountId);
        param.put("page", page);
        param.put("pageSize", pageSize);
        HttpEntity<Map> entity = new HttpEntity<Map>(param, headers);
        String response = restTemplate.postForObject(queryCertificatesStr,
                entity, String.class);
        log.info(response.toString());
        List<String> skuids = new ArrayList<>();
        ByteQueryResponseVO byteQueryResponseVO = JSON.parseObject(response, ByteQueryResponseVO.class);
        if (CommonUtil.isNotEmpty(byteQueryResponseVO.getData())) {
            ByteQueryDataVO byteQueryDataVO = byteQueryResponseVO.getData();
            List<ByteQueryDataOrdersVO> orders = byteQueryDataVO.getOrders();
            if (CommonUtil.isNotEmpty(orders)) {
                for (ByteQueryDataOrdersVO byteQueryDataOrdersVO : orders) {
                    List<ByteQueryDataCertificateVO> byteQueryDataCertificateVOList = byteQueryDataOrdersVO.getCertificates();
                    if (CommonUtil.isNotEmpty(byteQueryDataCertificateVOList)) {
                        for (ByteQueryDataCertificateVO byteQueryDataCertificateVO : byteQueryDataCertificateVOList) {
                            ByteQueryDataSkuInfoVO byteQueryDataSkuInfoVO = byteQueryDataCertificateVO.getSku_info();
                            String skuId = byteQueryDataSkuInfoVO.getThird_sku_id();
                            if (CommonUtil.isNotEmpty(skuId)) {
                                skuids.add(skuId);
                            }
                        }
                    }
                }
            }
        }
        //获取goodsId
        if (CommonUtil.isNotEmpty(skuids)) {
            Map<String, GoodsInfoVO> maps = getGoodIdByskuids(skuids, accountId);
            if (CommonUtil.isNotEmpty(maps)) {
                if (CommonUtil.isNotEmpty(byteQueryResponseVO.getData())) {
                    ByteQueryDataVO byteQueryDataVO = byteQueryResponseVO.getData();
                    List<ByteQueryDataOrdersVO> orders = byteQueryDataVO.getOrders();
                    if (CommonUtil.isNotEmpty(orders)) {
                        for (ByteQueryDataOrdersVO byteQueryDataOrdersVO : orders) {
                            List<ByteQueryDataCertificateVO> byteQueryDataCertificateVOList = byteQueryDataOrdersVO.getCertificates();
                            if (CommonUtil.isNotEmpty(byteQueryDataCertificateVOList)) {
                                for (ByteQueryDataCertificateVO byteQueryDataCertificateVO : byteQueryDataCertificateVOList) {
                                    ByteQueryDataSkuInfoVO byteQueryDataSkuInfoVO = byteQueryDataCertificateVO.getSku_info();
                                    String skuId = byteQueryDataSkuInfoVO.getThird_sku_id();
                                    if (CommonUtil.isNotEmpty(skuId)) {
                                        GoodsInfoVO goodsInfoVO = maps.get(skuId);
                                        byteQueryDataSkuInfoVO.setGoodPhoto(goodsInfoVO.getGoodPhoto());
                                        byteQueryDataSkuInfoVO.setGoodsName(goodsInfoVO.getGoodsName());
                                        byteQueryDataSkuInfoVO.setGoodId(goodsInfoVO.getGoodId());
                                    }
                                }
                            }
                        }
                    }
                }
            }
        }
        return JSON.toJSONString(byteQueryResponseVO);
    }

    @Override
    public String orderCanUse(String appId, String orderId) {
        log.info("CopcServiceImpl orderCanUse:{},", orderId);
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
        String accessToken = getClientToken(appId);
        headers.add("access-token", accessToken);
        Map<String, String> param = new HashMap<>();
        param.put("order_id", orderId);
        HttpEntity<Map> entity = new HttpEntity<Map>(param, headers);
        String response = restTemplate.postForObject(orderCanUseStr,
                entity, String.class);
        List<String> skuids = new ArrayList<>();
        ByteOrderCanUseResponseVO byteOrderCanUseResponseVO = JSON.parseObject(response, ByteOrderCanUseResponseVO.class);
        if (CommonUtil.isNotEmpty(byteOrderCanUseResponseVO.getData())) {
            List<ByteQueryDataCertificateVO> certificates = byteOrderCanUseResponseVO.getData().getCertificates();
            if (CommonUtil.isNotEmpty(certificates)) {
                for (ByteQueryDataCertificateVO certificate : certificates) {
                    ByteQueryDataSkuInfoVO byteQueryDataSkuInfoVO = certificate.getSku_info();
                    String skuId = byteQueryDataSkuInfoVO.getThird_sku_id();
                    if (CommonUtil.isNotEmpty(skuId)) {
                        skuids.add(skuId);
                    }
                }
            }
        }
        //获取goodsId
        if (CommonUtil.isNotEmpty(skuids)) {
            Map<String, GoodsInfoVO> maps = getGoodIdByskuids(skuids, "7221044683785373751");
            if (CommonUtil.isNotEmpty(maps)) {
                if (CommonUtil.isNotEmpty(byteOrderCanUseResponseVO.getData())) {
                    List<ByteQueryDataCertificateVO> certificates = byteOrderCanUseResponseVO.getData().getCertificates();
                    if (CommonUtil.isNotEmpty(certificates)) {
                        for (ByteQueryDataCertificateVO certificate : certificates) {
                            ByteQueryDataSkuInfoVO byteQueryDataSkuInfoVO = certificate.getSku_info();
                            String skuId = byteQueryDataSkuInfoVO.getThird_sku_id();
                            if (CommonUtil.isNotEmpty(skuId)) {
                                GoodsInfoVO goodsInfoVO = maps.get(skuId);
                                byteQueryDataSkuInfoVO.setGoodPhoto(goodsInfoVO.getGoodPhoto());
                                byteQueryDataSkuInfoVO.setGoodsName(goodsInfoVO.getGoodsName());
                                byteQueryDataSkuInfoVO.setGoodId(goodsInfoVO.getGoodId());
                            }
                        }
                    }
                }
            }
        }
        return JSON.toJSONString(byteOrderCanUseResponseVO);
    }

    @Override
    public String getPoiId(String account_id) {
        QueryWrapper<MerchantConfig> merchantConfigQueryWrapper = new QueryWrapper();
        merchantConfigQueryWrapper.eq("account_id", account_id);//启用的商户配置
        MerchantConfig merchantConfig = merchantConfigService.getOne(merchantConfigQueryWrapper);
        if (CommonUtil.isNotEmpty(merchantConfig)) {
            return merchantConfig.getOpenShopid();
        }
        return "";
    }

}
